<p style="font-size: 14px">NOVA TURMA</p>
<br />
<form>
    <p>Selecione o ano:
        <select id="anoTurma">
            <option value="<?= date('Y') ?>"><?= date('Y') ?></option>
            <option value="<?= date('Y')+1 ?>"><?= date('Y')+1 ?></option>
        </select>
    </p>
    <p>Selecione uma turma:
        <select id="turmaCod">
            <option value="">&nbsp;</option>
            <option value="A">A</option>
            <option value="B">B</option>
            <option value="C">C</option>
            <option value="D">D</option>
            <option value="E">E</option>
            <option value="F">F</option>
        </select>
    </p>
    <p>Selecione um turno:
        <select id="turnoCod">
            <option value="">&nbsp;</option>
            <option value="0">Matutino</option>
            <option value="1">Vespertino</option>
            <option value="2">Noturno</option>
        </select>
    </p>
    <p>Regular:
        <input type="checkbox" id="regular" checked value="0" />
    </p>
    <p>N&uacute;mero de vagas:
        <input id="qtdVagas" size="3" />
    </p>
    <input type="hidden" id="serieCod" value="<?= $serieCod ?>" />
    <input type="button" id="btnGravarTurma" value="Gravar Turma" />
</form>

<script>
    
    $('#btnGravarTurma').click(function(){
        
        var serieCod = jQuery('input[id="serieCod"]').val();
        var turmaCod = jQuery('select[id="turmaCod"]').val();
        var turnoCod = jQuery('select[id="turnoCod"]').val();
        var regular = jQuery('input[id="regular"]:checked').val();
        var qtdVagas = jQuery('input[id="qtdVagas"]').val();
        var anoTurma = jQuery('select[id="anoTurma"]').val();
        
        jQuery.ajax( {
            type: "POST",
            url: '?c=c_turma&m=gravarTurma',
            cache: false,
            data: {
                serieCod:serieCod,
                turmaCod:turmaCod,
                turnoCod:turnoCod,
                regular:regular,
                anoTurma:anoTurma,
                qtdVagas:qtdVagas
            },
            beforeSend: function (){
                $('#div_body').addClass("div_carregando");
            },
            complete:  function(){
                $('#div_body').removeClass("div_carregando");

            },
            success: function(data){
               
                var dados = data.split('@');
                
                if(dados[0] == true){
                    
                    $('#listaTurma').append(dados[1]);
                    jQuery(document).trigger('close.facebox');
                    
                }                    
                else
                    alert('Erro ao gravar. Tente novamente');
            }
        });
        
    });

</script>